package com.lanren.familybookapp.ui.table.presenter;

import com.lanren.common.base.impl.BasePresenter;
import com.lanren.familybookapp.ui.table.bean.InOutStatisticsBean;
import com.lanren.familybookapp.ui.table.bean.TotalStaticsBean;
import com.lanren.familybookapp.ui.table.interfaces.ITableModel;
import com.lanren.familybookapp.ui.table.model.TableModel;

/**
 * @ClassName MePresenter
 * @Description TODO
 * @Author chongheng.wang
 * @Date 2019/10/5 17:02
 * @Version 1.0
 */
public class TablePresenter extends BasePresenter<ITableModel.ITableView> {
    private TableModel tableModel;

    public TablePresenter(TableModel tableModel) {
        this.tableModel = tableModel;
    }

    public void getTotal(int bookId, String bookTime) {
        tableModel.getTotal(bookId, bookTime, new ITableModel.TableTotalModel() {
            @Override
            public void onError(int code, String msg) {
                mRootView.showError(code, msg);
            }

            @Override
            public void onSuccess(TotalStaticsBean totalStaticsBean) {
                mRootView.onSuccessTotal(totalStaticsBean);
            }
        });
    }

    public void getStatistics(int bookId, String bookTime, int inOut){
        tableModel.getStatistics(bookId, bookTime, inOut, new ITableModel.TableStaticsModel() {
            @Override
            public void onError(int code, String msg) {
                mRootView.showError(code, msg);
            }

            @Override
            public void onSuccess(InOutStatisticsBean inOutStatisticsBean) {
                mRootView.onSuccessStatics(inOutStatisticsBean);
            }
        });
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        if (tableModel != null) {
            tableModel.clearDisposable();
            tableModel = null;
        }
    }
}
